[#import "/framework/JGP.htm"  as JGP]
<!--
项目   jgp-cloud-parent
作者   LOUFEI [Gavin]
时间   2019-11-03
-->
[@JGP.head "修改角色"/]
[@JGP.body]
    <jgp-div _row="['40','*']" _runit="px">
        <jgp-tools slot="1-1">
            <jgp-btn _fn="save">保存</jgp-btn>
        </jgp-tools>
        <jgp-panel slot="2-1" _padding="10px" _border="right">
            <jgp-tree2 _id="tree" _root="角色树" _single="false" _icon="false"
                       _onload="initTree" _show_root="false"
                       _onchange="aaaa"
                       _lazy="false"
                       _url="/security/role-api-ctl/query-tree"></jgp-tree2>
        </jgp-panel>
    </jgp-div>
[/@JGP.body]

[@JGP.foot]
    <script>
        var userId = '${userId!''}';
        var selected;
        function initTree(){
            if(!selected){
                JGP.$get('/security/role-user-api-ctl/query-role-ids', {
                        userId:userId
                    },
                    function (result) {
                        if(result.flag){
                            selected = result.data.roles;
                            JGP.tree2('tree').setSelectedKeys(selected);
                        }
                    })
            }
        }
        function save() {
            var selected = JGP.tree2('tree').getSelected();
            if (selected.length === 0) {
                JGP.$warn('没有选择角色');
                return;
            }
            var roleIds = [];
            for (var i = 0; i < selected.length; i++) {
                roleIds.push(selected[i].id);
            }
            JGP.$postJson('/security/role-user-api-ctl/modify-user-role', {
                    roleIds: roleIds,
                    userId: userId
                },
                function () {
                    JGP.$alert('角色修改成功');
                    JGP.$close(userId)
                }, function () {
                    JGP.$error('错误');
                })

        }
    </script>
[/@JGP.foot]